var _CollapseToVal=Array();
var _CollapseTimeOut=Array();
function collapse(btn,obj,minval,maxval,speed,padding,setclass){
	if(typeof(speed)=="undefined"){
		speed = 10;
	}
	
	if(typeof(padding)=="undefined"){
		padding=10;
	}
	
	if(_CollapseTimeOut[obj.id]){
		clearTimeout(_CollapseTimeOut[obj.id]);
	}
	var h = obj.offsetHeight;
	var diffmin = Math.abs(h-minval);
	var diffmax = Math.abs(h-maxval);
	
	obj.style.overflow='hidden';
	if(!obj.id){
		obj.id = "col"+Math.round(Math.random()*100000);
	}
	
	if(diffmin>diffmax){	// collapse
		_CollapseToVal[obj.id]=minval;
		_collapse(obj.id,'-1',speed,padding,setclass);
		if(setclass==1)
		btn.className = "expand";
	}else{					// expand
		_CollapseToVal[obj.id]=maxval;
		_collapse(obj.id,'1',speed,padding,setclass);
		if(setclass==1)
		btn.className = "collapse";
	}
}
function _collapse(id,amount,speed,padding,setclass){
	var obj = document.getElementById(id);
	amount = parseInt(amount);
	if(obj){
		var h = obj.offsetHeight-(2*padding);
		//alert(h)
		
		var diff = Math.abs(h-_CollapseToVal[id]);
		var fix = amount*Math.round(diff/2);
		var test=Math.abs((h+fix)-_CollapseToVal[id]);
		if(test>5){
			//alert(test+"\n"+h+"+"+fix+"="+(h+fix));
			obj.style.height = Math.abs(h+fix)+"px";
			//window.status = obj.style.height;
			//alert("H:"+h+" ["+obj.style.height+"]\nTo:"+toval+"\ndiff:"+diff+"\nstep:"+fix);
			_CollapseTimeOut[obj.id] = setTimeout('_collapse("'+id+'","'+amount+'","'+speed+'","'+padding+'","'+setclass+'")',100/speed);
		}else{
			obj.style.height = _CollapseToVal[obj.id]+"px";
			if(_CollapseTimeOut[obj.id]){
				clearTimeout(_CollapseTimeOut[obj.id]);
				//alert("done")
			}
		}
	}else if(_CollapseTimeOut[obj.id]){
		clearTimeout(_CollapseTimeOut[obj.id]);
	}
}